1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module pango.PgScriptIter;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.c.functions;
30 private import gobject.ObjectG;
31 private import linker.Loader;
32 private import pango.c.functions;
33 public  import pango.c.types;
34 
35 
36 /**
37  * A `PangoScriptIter` is used to iterate through a string
38  * and identify ranges in different scripts.
39  */
40 public class PgScriptIter
41 {
42 	/** the main Gtk struct */
43 	protected PangoScriptIter* pangoScriptIter;
44 	protected bool ownedRef;
45 
46 	/** Get the main Gtk struct */
47 	public PangoScriptIter* getPgScriptIterStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return pangoScriptIter;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected void* getStruct()
56 	{
57 		return cast(void*)pangoScriptIter;
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (PangoScriptIter* pangoScriptIter, bool ownedRef = false)
64 	{
65 		this.pangoScriptIter = pangoScriptIter;
66 		this.ownedRef = ownedRef;
67 	}
68 
69 	~this ()
70 	{
71 		if ( Linker.isLoaded(LIBRARY_PANGO[0]) && ownedRef )
72 			pango_script_iter_free(pangoScriptIter);
73 	}
74 
75 
76 	/** */
77 	public static GType getType()
78 	{
79 		return pango_script_iter_get_type();
80 	}
81 
82 	/**
83 	 * Create a new `PangoScriptIter`, used to break a string of
84 	 * Unicode text into runs by Unicode script.
85 	 *
86 	 * No copy is made of @text, so the caller needs to make
87 	 * sure it remains valid until the iterator is freed with
88 	 * [method@Pango.ScriptIter.free].
89 	 *
90 	 * Params:
91 	 *     text = a UTF-8 string
92 	 *     length = length of @text, or -1 if @text is nul-terminated
93 	 *
94 	 * Returns: the new script iterator, initialized
95 	 *     to point at the first range in the text, which should be
96 	 *     freed with [method@Pango.ScriptIter.free]. If the string is
97 	 *     empty, it will point at an empty range.
98 	 *
99 	 * Since: 1.4
100 	 *
101 	 * Throws: ConstructionException GTK+ fails to create the object.
102 	 */
103 	public this(string text, int length)
104 	{
105 		auto __p = pango_script_iter_new(Str.toStringz(text), length);
106 
107 		if(__p is null)
108 		{
109 			throw new ConstructionException("null returned by new");
110 		}
111 
112 		this(cast(PangoScriptIter*) __p);
113 	}
114 
115 	/**
116 	 * Frees a `PangoScriptIter`.
117 	 *
118 	 * Since: 1.4
119 	 */
120 	public void free()
121 	{
122 		pango_script_iter_free(pangoScriptIter);
123 		ownedRef = false;
124 	}
125 
126 	/**
127 	 * Gets information about the range to which @iter currently points.
128 	 *
129 	 * The range is the set of locations p where *start <= p < *end.
130 	 * (That is, it doesn't include the character stored at *end)
131 	 *
132 	 * Note that while the type of the @script argument is declared
133 	 * as `PangoScript`, as of Pango 1.18, this function simply returns
134 	 * `GUnicodeScript` values. Callers must be prepared to handle unknown
135 	 * values.
136 	 *
137 	 * Params:
138 	 *     start = location to store start position of the range
139 	 *     end = location to store end position of the range
140 	 *     script = location to store script for range
141 	 *
142 	 * Since: 1.4
143 	 */
144 	public void getRange(out string start, out string end, out PangoScript script)
145 	{
146 		char* outstart = null;
147 		char* outend = null;
148 
149 		pango_script_iter_get_range(pangoScriptIter, &outstart, &outend, &script);
150 
151 		start = Str.toString(outstart);
152 		end = Str.toString(outend);
153 	}
154 
155 	/**
156 	 * Advances a `PangoScriptIter` to the next range.
157 	 *
158 	 * If @iter is already at the end, it is left unchanged
159 	 * and %FALSE is returned.
160 	 *
161 	 * Returns: %TRUE if @iter was successfully advanced
162 	 *
163 	 * Since: 1.4
164 	 */
165 	public bool next()
166 	{
167 		return pango_script_iter_next(pangoScriptIter) != 0;
168 	}
169 }